//
//  ZYCNoticeDetailBottomView.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/19.
//

#import "ZYCNoticeDetailBottomView.h"
@interface ZYCNoticeDetailBottomView ()
@property (nonatomic, strong)UIButton *statusButton;
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
@end

@implementation ZYCNoticeDetailBottomView

- (void)setStatus:(ZYCNoticeStatus)status{
    _status = status;
    if (status == ZYCNoticeStatusIsRead) {
        [_statusButton setTitle:@"已读" forState:UIControlStateNormal];
        self.gradientLayer.colors = @[(__bridge id)HEX_RGB(@"#CCCCCC").CGColor,
                                 (__bridge id)HEX_RGB(@"CCCCCC").CGColor];
    }else{
        [_statusButton setTitle:@"读" forState:UIControlStateNormal];
        self.gradientLayer.colors = @[(__bridge id)HEX_RGB(@"#F5EBA7").CGColor,
                                 (__bridge id)HEX_RGB(@"#009043").CGColor];
    }
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(@"#FAFAFA");
        [self addSubview:self.statusButton];
        [self.statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(240.0f, 40.0f));
        }];
 
    }
    return self;
}


- (void)addGradientLayer{
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.startPoint = CGPointMake(0, 0);
    self.gradientLayer.endPoint = CGPointMake(1, 0);

    self.gradientLayer .locations = @[@(0.3),@(1.0f)];
    self.gradientLayer .frame = _statusButton.bounds;
    self.gradientLayer .cornerRadius = 24;
    [self.statusButton.layer insertSublayer:self.gradientLayer  atIndex:0];
}

- (UIButton *)statusButton {
    if (!_statusButton) {
        _statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _statusButton.frame = CGRectMake(0,0, kScreenWidth - 2 * 68, 40);
        [_statusButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
        [_statusButton addTarget:self action:@selector(clickStatusAction:) forControlEvents:UIControlEventTouchUpInside];
        _statusButton.layer.cornerRadius = 18;
        _statusButton.layer.masksToBounds = YES;
        
        [self addGradientLayer];

    }
    return _statusButton;
}

- (void)clickStatusAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(noticeDetailBottomViewDidClickReadStatus:)]) {
        [self.delegate noticeDetailBottomViewDidClickReadStatus:self.status];
    }
}

@end
